package com.erps.config;

import java.util.List;

import com.erps.CommonUtils.AppConfig;
import com.erps.CommonUtils.StringEx;
import com.erps.model.MessageModel;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

public class MessageController extends Controller {
	public void index() {
		int msg_type = StringEx.getInt(getPara("msg_type"), 1);
		MessageModel message = getModel(MessageModel.class);
		int pagenumber = StringEx.getInt(getPara("pagenum"), 1);
		int pagesize = StringEx.getInt(getPara("pagesize"), 5);
		String user_id = getSessionAttr(AppConfig.SESSION_USERID);

		Page<MessageModel> page = message.paginate(pagenumber, pagesize, user_id, msg_type);
		List<MessageModel> list = page.getList();

		int pages = page.getTotalPage();

		System.out.println("TotalRow:" + page.getTotalRow());
		System.out.println("PageSize:" + page.getPageSize());
		System.out.println("ToalPage:" + pages);
		System.out.println("pagenumber:" + page.getPageNumber());
		setAttr("messages", list);
		setAttr("pagenumber", page.getPageNumber());// 当前页面;
		setAttr("pages", pages);// 符合条件的总记录数
		render("messege.ftl");

	}
}
